<template>
    <el-table :data="tableParamList" stripe > 
        <el-table-column prop="control" label="控制值" align="center" v-if="showControl"></el-table-column>  
        <el-table-column prop="controL_NAME" label="控制值名称" align="center"></el-table-column> 
        <el-table-column prop="value" label="取值" align="center">
            <template slot-scope="scope">
            <el-input placeholder="请输入参数值" v-model="scope.row.value" clearable
            size="small" @change="handleSetListValue(scope.row)" @clear="handleDelList(scope.row.id)"></el-input>
            </template>
        </el-table-column> 
        <el-table-column prop="unit" label="单位" align="center"></el-table-column> 
    </el-table>
</template>
<script>
import {indexControlList,indexControlDel,indexControlSet } from '@/api/https'
export default ({
    props:{
        indeX_ID:{
            type:Number,
            default:0
        },
        showControl:{
            type:Boolean,
            default:false
        }
    },
    data() {
        return {
            tableParamList:[]
        }  
    },
    mounted(){
        this.onGetControlList()
    },
    beforeDestroy(){
        this.tableParamList = []
    },
    methods:{
        onGetControlList(){
            indexControlList({
                INDEX_ID:this.indeX_ID
            }).then(res=>{
                if(res.isSuccess && res.data && res.data.length > 0 ){
                    this.tableParamList = res.data
                }else{
                    this.tableParamList = []
                }
            })
        },
        handleSetListValue(data){
            indexControlSet({
                id:data.id,
                indeX_ID:this.indeX_ID,
                control:data.control,
                controL_NAME:data.controL_NAME,
                value:Number(data.value),
                unit:data.unit,
                remark:data.remark
            }).then(res=>{
                if(res.isSuccess){
                    this.onGetControlList()
                }else{
                    this.$message.error(res.errorMessage)
                }
            })
        },
        handleDelList(id){
            indexControlDel({ID:id}).then(res=>{
                if(res.isSuccess){
                    this.onGetControlList()
                }else{
                this.$message.error(res.errorMessage)
                }
            })
        },
    }
})
</script>
<style scoped>
</style>
